package rock.loadbalance;

import rock.remoting.dto.RpcRequest;

import java.util.List;

public abstract class AbstractLoadBalance implements LoadBalance {
    @Override
    public String selectServiceAddress(List<String> serviceAddresses, RpcRequest request) {
        if (null == serviceAddresses || serviceAddresses.isEmpty()) {
            return null;
        }

        if (serviceAddresses.size() == 1) {
            return serviceAddresses.get(0);
        }

        return doSelect(serviceAddresses, request);
    }

    /**
     * 抽象方法
     * @param serviceAddresses 可选list
     * @param request rpc request
     * @return
     */
    protected abstract String doSelect(List<String> serviceAddresses, RpcRequest request);
}
